//迭代阶乘
let sum = 0;
function add(num) {
    if (num != 0) {
        sum = num + sum
        add(num - 1)
    }
    return sum
}
function sums(n) {
    if (n === 1) {
        return 1;
    } else {
        return n + sums(n - 1);
    }
}
console.log(sums(1));
console.log(add(4));

//斐波那契函数
function fibonacci(n) {
    if (n <= 0) {
      return [];
    } else if (n === 1) {
      return [0];
    } else if (n === 2) {
      return [0, 1];
    } else {
      const sequence = [0, 1];
      for (let i = 2; i < n; i++) {
        const nextNum = sequence[i - 1] + sequence[i - 2];
        sequence.push(nextNum);
      }
      return sequence;
    }
  }
  


